import { useRef } from "react";

function Son(props) {
  //   注意：props是只读的
  console.log("接受传值", props);

  const refbox = useRef(null);
  const showDom = () => {
    console.log("获取dom节点", refbox.current);
  };

  const sendInfo = () => {
    props.getSonInfo('hello father')
  }

  return (
    <div>
      <h4 style={{ color: "blue", fontSize: "14px" }} ref={refbox}>
        子组件3：获取dom元素用ref，父子组件通信
      </h4>
      <button onClick={showDom}>获取dom</button>
      <div>{props.message}</div>
      {props.children}
      <br/>
      <button onClick={sendInfo}>给父组件传值</button>
    </div>
  );
}
export default Son;
